package business.article.entities;

import article.entities.ArticleVO;
import article.entities.IngredientVO;

public class Article {

	protected String name, desc;
	protected int primaryKey;
	protected double price;
	protected Ingredient[] ingr;
	protected Category cat;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public Ingredient[] getIngr() {
		return ingr;
	}

	public void setIngr(Ingredient[] ingr) {
		this.ingr = ingr;
	}

	public int getPrimaryKey() {
		return primaryKey;
	}

	public Category getCat() {
		return cat;
	}

	public Article(String name, String desc, int primaryKey, double price,
			Ingredient[] ingr, Category cat) {
		this.name = name;
		this.desc = desc;
		this.primaryKey = primaryKey;
		this.price = price;
		this.ingr = ingr;
		this.cat = cat;
	}

	public Article(String name, String desc, double price, Ingredient[] ingr,
			Category cat) {
		this.name = name;
		this.desc = desc;
		this.price = price;
		this.ingr = ingr;
		this.cat = cat;
	}

	public Article(ArticleVO art) {
		if (art != null) {
			this.name = art.getName();
			this.desc = art.getDesc();
			this.price = art.getPrice();
			this.primaryKey = art.getPrimaryKey();

			if (art.getIngr() != null) {
				this.ingr = new Ingredient[art.getIngr().length];
				int i = 0;
				for (IngredientVO o : art.getIngr()) {
					this.ingr[i] = new Ingredient(o);
					i++;
				}
			} else
				this.ingr = null;

			if (art.getCat() != null) {
				this.cat = new Category(art.getCat());
			} else
				this.cat = null;
		}
	}

	public ArticleVO toVO() {
		IngredientVO[] temp;
		if (this.ingr != null) {
			temp = new IngredientVO[this.ingr.length];
			int i = 0;
			for (Ingredient o : this.ingr) {
				temp[i] = o.toVO();
				i++;
			}
		} else
			temp = null;
		return new ArticleVO(this.name, this.desc, this.primaryKey, this.price,
				temp, (this.cat!=null) ? this.cat.toVO() : null);
	}
	
	public int compareTo(Article art){
		if(this.primaryKey==art.getPrimaryKey())
			return 0;
		else
			return -1;
	}

}
